home *** CD-ROM | disk | FTP | other *** search
- Path: erinews.ericsson.se!usenet
- From: etmbgom@ericsson.se (Ben van Gompel)
- Newsgroups: comp.lang.c++
- Subject: Re: Reverting of big array ?
- Date: 27 Mar 1996 15:54:59 GMT
- Organization: Ericsson Telecommunicatie BV.
- Message-ID: <4jbock$s7j@erinews.ericsson.se>
- References: <31587ACF.59D9@teleport.com>
- Reply-To: etmbgom@ericsson.se
- NNTP-Posting-Host: worf.etm.ericsson.se
-
- In article <31587ACF.59D9@teleport.com>, GHouck <hksys@teleport.com> writes:
- > Thomas wrote:
- > > I need to revert an array (of chars).
- > > I used the folowing code:( l=length of array)
- > >
- > > char *rev=new char[l+1];
- > > for(i=l-1,j=0;i>=0;i--,j++) rev[j]=seq[i];
- > > rev[j]='\0';
- > >
- > > this code works, but is terribly slow, when using an string with
- > > size ~ 6000.
- > > doing the same with the unix command 'rev' takes 1/2 second.
- > > Any ideas ???Thomas,
- > It might not be much faster, but I usually use the following:
- >
- > for( i=0; i<numChars/2; i++ )
- > strChars[i] = strChars[numChars-i-1];
-
- That won't work.
- You better use something like:
-
- char* newChars = new char[numChars+1]
- for( i=0; i<numChars; i++ )
- {
- newChars[i] = oldChars[numChars-i-1];
- }
- newChars[numChars] = '\0';
-
- But still, this won't be fast enough I'd guess.
-
- Regards, Ben
-
-